home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / tpb4_src.zip / TYPEFILE.PAS < prev    next >
Pascal/Delphi Source File  |  1988-09-13  |  10KB  |  361 lines

  1. { TPBoard 4.2 Copyright (c) 1987,88 by Jon Schneider & Rick Petersen  
  2.   Portions Copyright (c) 1986,87 by Steve Fox and Les Archambault  
  3.   
  4.   Last modified  ::  7-12-88 4:42 pm 
  5. }
  6.  
  7. {$R-}                             {Range checking off}
  8. {$B-}                             {Boolean complete evaluation off}
  9. {$S-}                             {Stack checking off}
  10. {$I+}                             {I/O checking on}
  11. {$N-}                             {No numeric coprocessor}
  12.  
  13. Unit TypeFile;
  14.  
  15. Interface
  16.  
  17. Uses
  18.   TPCrt, Globals, TPDOS,
  19.   Core1, Core2, Dirs, DeArc;
  20.   
  21.   
  22. procedure SendText;
  23.  
  24.  
  25.   {==========================================================================}
  26.   
  27.   
  28. Implementation
  29.  
  30.  
  31.  
  32.   procedure SendText;
  33.   
  34.   const
  35.     bufsize         = 128;
  36.     bufblocks       = 128;
  37.     
  38.   var
  39.     This            : FilePtr;
  40.     Xfrname         : DosFileName;
  41.     XfrFile         : untype_file;
  42.     Buffer          : array[1..bufsize] of Byte;
  43.     ErrMsg          : StrStd;
  44.     FileType        : Str3;
  45.     
  46.     
  47.     function check_extension : Boolean;
  48.     
  49.     var
  50.       FileType        : string[3];
  51.       i               : Integer;
  52.       
  53.     begin
  54.       i := Pos('.', Xfrname);
  55.       if 0 = i then
  56.         FileType := ''
  57.       else
  58.         FileType := Copy(Xfrname, Succ(i), Length(Xfrname));
  59.       if (FileType = 'COM') or (FileType = 'OBJ') or (FileType[2] = 'Z')
  60.       or (FileType = 'EXE') or (FileType = 'LBR') or (FileType = 'ARC') then
  61.         begin
  62.           check_extension := False;
  63.           WriteLn(Com, 'Sorry, you can''t type ', FileType, ' files.');
  64.         end
  65.       else
  66.         check_extension := True;
  67.     end;
  68.     
  69.     
  70.     procedure SendFile(var XfrFile     : untype_file;
  71.                        remaining       : LongInt);
  72.       { Send a squeezed or ASCII file }
  73.       
  74.     const
  75.       recognize       = $FF76;
  76.       DLE             = $90;
  77.       
  78.     var
  79.       EndOfFile,
  80.       squeezed,
  81.       connected       : Boolean;
  82.       i, x,
  83.       BufferPtr,
  84.       bpos, curin,
  85.       repct,
  86.       lastc,
  87.       line_count,
  88.       NoOfRecs,
  89.       result          : Integer;
  90.       dnode           : array[0..255, 0..1] of Integer;
  91.       
  92.       
  93.       function getc   : Integer;
  94.         { Get an 8 bit value from the input buffer - read block if necessary }
  95.         
  96.       begin
  97.         if BufferPtr > bufsize then
  98.           begin
  99.             NoOfRecs := min(bufblocks, remaining);
  100.             if NoOfRecs < bufblocks then
  101.               Buffer[Succ(NoOfRecs)] := 26;
  102.             EndOfFile := (NoOfRecs = 0);
  103.             if not EndOfFile then
  104.               BlockRead(XfrFile, Buffer, NoOfRecs, result);
  105.             remaining := remaining-result;
  106.             BufferPtr := 1
  107.           end;
  108.         getc := Buffer[BufferPtr];
  109.         Inc(BufferPtr)
  110.       end;
  111.       
  112.       
  113.       function getw   : Word;
  114.         { Get a 16 bit value from the input buffer }
  115.         
  116.       var
  117.         temp            : Byte;
  118.         
  119.       begin
  120.         temp := getc;
  121.         getw := temp+Swap(getc)
  122.       end;
  123.       
  124.       
  125.       procedure BuildTree;
  126.         { Build decode tree }
  127.         
  128.       var
  129.         i               : Integer;
  130.         CheckSum,
  131.         numnodes        : Word;
  132.         
  133.       begin
  134.         ErrMsg := '';
  135.         if recognize = getw       { Is it really a squeezed file? }
  136.         then
  137.           begin
  138.             CheckSum := getw;     { Get checksum }
  139.             Xfrname := '';
  140.             i := getc;            { Build original file name }
  141.             while i <> 0 do
  142.               begin
  143.                 Xfrname := Xfrname+Upcase(Chr(i));
  144.                 i := getc
  145.               end;
  146.             numnodes := getw;     { Get the number of nodes in tree }
  147.             if (0 < numnodes) and (numnodes <= 256) then
  148.               for i := 0 to Pred(numnodes) do
  149.                 begin
  150.                   dnode[i, 0] := Integer(getw);
  151.                   dnode[i, 1] := Integer(getw);
  152.                 end
  153.             else
  154.               begin
  155.                 ErrMsg := 'Invalid decode tree size.';
  156.                 squeezed := False
  157.               end
  158.           end
  159.         else
  160.           squeezed := False
  161.       end;
  162.       
  163.       
  164.       function gethuff : Integer;
  165.         { Get character coding }
  166.         
  167.       var
  168.         i               : Integer;
  169.         
  170.       begin
  171.         i := 0;
  172.         repeat
  173.           Inc(bpos);
  174.           if bpos > 7 then
  175.             begin
  176.               curin := getc;
  177.               bpos := 0
  178.             end
  179.           else
  180.             curin := curin shr 1;
  181.           i := dnode[i, curin and $0001]
  182.         until i < 0;
  183.         i := -Succ(i);
  184.         if i = 0 then
  185.           gethuff := 26
  186.         else
  187.           gethuff := i
  188.       end;
  189.       
  190.       
  191.       function getcr  : Integer;
  192.       
  193.       var
  194.         C               : Integer;
  195.         
  196.       begin
  197.         if repct > 0 then
  198.           begin
  199.             repct := Pred(repct);
  200.             getcr := lastc
  201.           end
  202.         else
  203.           begin
  204.             C := gethuff;
  205.             if C = DLE then
  206.               begin
  207.                 repct := gethuff;
  208.                 if repct = 0 then
  209.                   getcr := DLE
  210.                 else
  211.                   begin
  212.                     repct := repct-2;
  213.                     getcr := lastc
  214.                   end
  215.               end
  216.             else
  217.               begin
  218.                 getcr := C;
  219.                 lastc := C
  220.               end
  221.           end
  222.       end;
  223.       
  224.     begin                         { SendFile }
  225.       connected := Online;
  226.       if (not connected) then
  227.         SetSect(SetName)
  228.       else
  229.         begin
  230.           i := Pos('.', Xfrname);
  231.           if i = 0 then
  232.             FileType := ''
  233.           else
  234.             FileType := Copy(Xfrname, Succ(i), Length(Xfrname));
  235.           squeezed := ('Q' = FileType[2]);
  236.           repct := 0;
  237.           bpos := 8;
  238.           ErrMsg := '';
  239.           BufferPtr := MaxInt;    { Force a read the first time }
  240.           EndOfFile := False;
  241.           if remaining > 0 then
  242.             begin
  243.               if squeezed then
  244.                 BuildTree;
  245.               if check_extension then
  246.                 begin
  247.                   line_count := 0;
  248.                   if squeezed then
  249.                     begin
  250.                       WriteLn(Com, '      ---> ', Xfrname);
  251.                       x := getcr
  252.                     end
  253.                   else
  254.                     x := getc;
  255.                   while (not brk) and (not EndOfFile) and (x <> 26) and
  256.                   ((line_count < line_abort) or (line_abort = 0) or
  257.                     (user_rec.access = 255)) do
  258.                     begin
  259.                       if x = Integer(TAB) then
  260.                         for i := 1 to (8-(WhereX mod 8)) do
  261.                           Write(Com, ' ')
  262.                       else
  263.                         Write(Com, Chr(x));
  264.                       if (user_rec.lines <> 99) and (Chr(x) = LF) then
  265.                         begin
  266.                           Inc(line_count);
  267.                           if line_count mod user_rec.lines = 0 then
  268.                             pause
  269.                         end;
  270.                       if squeezed then
  271.                         x := getcr
  272.                       else
  273.                         x := getc
  274.                     end;
  275.                   if ((line_count >= line_abort) and (line_abort <> 0) and
  276.                     (user_rec.access < 255)) then
  277.                     begin
  278.                       WriteLn(Com);
  279.                       WriteLn(Com, 'Sorry, you can only ''Type'' ',
  280.                         line_abort, ' lines.');
  281.                     end;
  282.                 end
  283.             end
  284.           else
  285.             ErrMsg := 'Missing or empty input file.';
  286.           if ErrMsg <> '' then
  287.             WriteLn(Com, ErrMsg)
  288.         end;
  289.     end;
  290.     
  291.     
  292.   begin                           { SendText }
  293.     abort := False;
  294.     Xfrname := correct_fn(prompt('File name', 12, 'ES'));
  295.     if in_arc then
  296.       begin
  297.         This := ArcBase;
  298.         while (This <> nil) and (Xfrname <> compress_fn(This^.fname)) do
  299.           This := This^.next;
  300.         if This <> nil then
  301.           begin
  302.             SetSect(SetName);
  303.             if check_extension then
  304.               TypeArc(ArcReq, Xfrname);
  305.             SetSect(HomName);
  306.           end
  307.         else
  308.           begin
  309.             WriteLn(Com, Xfrname, ' not found.');
  310.             Xfrname := ''
  311.           end;
  312.       end;
  313.     if (Xfrname <> '') and (not in_arc) then
  314.       begin
  315.         if in_library then
  316.           This := LibBase
  317.         else
  318.           This := DirBase;
  319.         while (This <> nil) and (Xfrname <> compress_fn(This^.fname)) do
  320.           This := This^.next;
  321.         if This <> nil then
  322.           begin
  323.             SetSect(HomName);
  324.             log(6, Xfrname);
  325.             SetSect(SetName);
  326.             if in_library then
  327.               begin
  328.                 {$I-}
  329.                 Assign(libr_file, LibReq);
  330.                 Reset(libr_file, 1);
  331.                 Seek(libr_file, This^.index*128) {$I+} ;
  332.                 if IoResult = 0 then
  333.                   SendFile(libr_file, This^.fsize*128);
  334.                 Close(libr_file)
  335.               end
  336.             else
  337.               begin
  338.                 Assign(XfrFile, Xfrname);
  339.                 Reset(XfrFile, 1);
  340.                 SendFile(XfrFile, FileSize(XfrFile));
  341.                 Close(XfrFile);
  342.                 if in_arc then
  343.                   begin
  344.                     Erase(XfrFile);
  345.                     SetSect(HomName);
  346.                     ReadDir(DirEntries, DirSpace, DirBase);
  347.                     new_dir := False
  348.                   end;
  349.               end;
  350.             SetSect(HomName);
  351.             log(7, '')
  352.           end
  353.         else
  354.           WriteLn(Com, Xfrname, ' not found.')
  355.       end;
  356.   end;
  357.   
  358.   
  359. end.                              { of TYPEFILE.PAS}
  360. 
  361.